<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Subcribe_model extends Model
{
	private $_host;
	private $_dbname;
	private $_username;
	private $_password;
	private $_port;
	
	function Subcribe_model()
	{
		parent::Model();
		
		$host = $this->db->hostname;
		$arrHost = explode(':',$host);
		
		$this->_host = trim($arrHost[0]);
		$this->_dbname = $this->db->database;
		$this->_username = $this->db->username;
		$this->_password = $this->db->password;
		$this->_port = $this->db->port;
	}
	
	function get_list($status, $cPage, $numItem)
	{
		$data = array();
        $data['list']=array();
		$data['iCount'] = 0;
		$data['pCount'] = 0;
		$start = ($cPage - 1) * $numItem;
				
		$iconn = mysqli_connect($this->_host, $this->_username, $this->_password, $this->_dbname, $this->_port);
		mysqli_multi_query($iconn, "CALL selfserving_admin_subcribe_get_list('$status', '$start', '$numItem');") or die(mysqli_error($iconn));
		
		$result = mysqli_store_result($iconn);
		while($row = mysqli_fetch_array($result))
		{
			$data['list'][] = $row;
		}
		
		mysqli_free_result($result);
		mysqli_next_result($iconn);
        $result = mysqli_store_result($iconn);
        while($row1 = mysqli_fetch_array($result))
		{
			$data['iCount'] = $row1[0];
		}
		mysqli_free_result($result);
		mysqli_close($iconn);
		
		$data['pCount'] = ($data['iCount'] > $numItem) ? ceil($data['iCount']/$numItem) : 1;
		
		return $data;
	}
	
	function get_list_webmaster($cPage, $numItem)
	{
		$data = array();
        $data['list']=array();
		$data['iCount'] = 0;
		$data['pCount'] = 0;
		$start = ($cPage - 1) * $numItem;
				
		$iconn = mysqli_connect($this->_host, $this->_username, $this->_password, $this->_dbname, $this->_port);
		mysqli_multi_query($iconn, "CALL selfserving_admin_webmster_get_list('$start', '$numItem');") or die(mysqli_error($iconn));
		
		$result = mysqli_store_result($iconn);
		while($row = mysqli_fetch_array($result))
		{
			$data['list'][] = $row;
		}
		
		mysqli_free_result($result);
		mysqli_next_result($iconn);
        $result = mysqli_store_result($iconn);
        while($row1 = mysqli_fetch_array($result))
		{
			$data['iCount'] = $row1[0];
		}
		mysqli_free_result($result);
		mysqli_close($iconn);
		
		$data['pCount'] = ($data['iCount'] > $numItem) ? ceil($data['iCount']/$numItem) : 1;
		
		return $data;
	}
 }